package com.jprocms.module.cms.controller.admin.channel.dto;

import cn.hutool.core.collection.CollUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 栏目规则 dto
 *
 * @author jprocms
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Schema(description = "管理后台 - 栏目规则配置 Request VO")
public class ChannelRuleDto {

    /***************来源设置******************************/
    @NotEmpty(message = "来源状态设置不能为空")
    @Schema(description = "来源状态设置 1:草稿,4待发布,5-发布状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private List<Integer> contentSourceStatuses;

    @Schema(description = "文档创建时间晚于")
    private LocalDateTime contentCreateTimeBegin;

    @Schema(description = "文档创建时间早于")
    private LocalDateTime contentCreateTimeEnd;

    @Schema(description = "模糊匹配的标题")
    private List<String> titles;

    @NotEmpty(message = "来源栏目设置不能为空")
    @Schema(description = "来源栏目")
    private List<ChannelRuleSourceDto> sourceChannels;

    /***************目标设置******************************/

    @Schema(description = "栏目id")
    @NotNull(message = "栏目id不能为空")
    private Long channelId;

    @Range(min = 1, max = 3, message = "采集方式 1-复制,2-引用")
    @Schema(description = "采集方式 1-复制,2-链接型引用,3-镜像型引用", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer collectionType;

    @Range(min = 1, max = 5)
    @Schema(description = "状态设置 1:草稿,5-发布状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer contentStatus;


    @NotNull(message = "采集设置不能为空")
    @Schema(description = "采集设置 1-开启,0-关闭", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer status;

    public List<String> getTitles() {
        List<String> tits = titles;
        if (CollUtil.isEmpty(tits)) {
            return null;
        }
        return titles.stream().filter(c -> StringUtils.isNotBlank(c)).collect(Collectors.toList());
    }
}
